﻿using System; 
using System.Reflection; 
namespace docmgr.Model { 
                           
	public class DocReadLog{ 	

		#region 私有属性成员 
		
		int m_ID; //ID 
		int m_DocumentID; //DocumentID 
		int m_LeaderId; //发起人 
		DateTime m_StartDate; //StartDate 
		string m_Status; //Status 
		DateTime m_ReadDate; //ReadDate 
		int m_ReadUserID; //ReadUserID 
 
		protected string m_Tag; // 预定义属性 
		
		#endregion
		
		#region 构造函数 Constructors 
		public DocReadLog(){
					// m_ID = 0 ;
		// m_DocumentID = 0 ;
		// m_LeaderId = 0 ;
		// m_StartDate = System.DateTime.Now ;
		// m_Status = "" ;
		// m_ReadDate = System.DateTime.Now ;
		// m_ReadUserID = 0 ;

		}
		//public DocReadLog(int ID,int DocumentID,int LeaderId,DateTime StartDate,string Status,DateTime ReadDate,int ReadUserID, string Tag){
					// m_ID = ID ;
		// m_DocumentID = DocumentID ;
		// m_LeaderId = LeaderId ;
		// m_StartDate = StartDate ;
		// m_Status = Status ;
		// m_ReadDate = ReadDate ;
		// m_ReadUserID = ReadUserID ;

			//m_Tag = Tag;
		//}
		#endregion
		
		#region 公共属性成员 
		

		/// <summary>
		/// ID
		/// <summary>
		public int ID 
		{
                                         get { return m_ID; }
                                         set { m_ID = value;}
		}


		/// <summary>
		/// DocumentID
		/// <summary>
		public int DocumentID 
		{
                                         get { return m_DocumentID; }
                                         set { m_DocumentID = value;}
		}


		/// <summary>
		/// 发起人
		/// <summary>
		public int LeaderId 
		{
                                         get { return m_LeaderId; }
                                         set { m_LeaderId = value;}
		}


		/// <summary>
		/// StartDate
		/// <summary>
		public DateTime StartDate 
		{
                                         get { return m_StartDate; }
                                         set { m_StartDate = value;}
		}


		/// <summary>
		/// Status
		/// <summary>
		public string Status 
		{
                                         get { return m_Status; }
                                         set { m_Status = value;}
		}


		/// <summary>
		/// ReadDate
		/// <summary>
		public DateTime ReadDate 
		{
                                         get { return m_ReadDate; }
                                         set { m_ReadDate = value;}
		}


		/// <summary>
		/// ReadUserID
		/// <summary>
		public int ReadUserID 
		{
                                         get { return m_ReadUserID; }
                                         set { m_ReadUserID = value;}
		}


		 
        /// <summary>
		/// 附加备用属性
		/// <summary>
		public string Tag {
			get { return m_Tag; }
			set { m_Tag = value; }
		}
		#endregion
		
        #region 扩展公共属性
		//-
		protected static string[] m_FiledsInfo=new string[]{
		  		"ID,int,ID",
		"DocumentID,int,DocumentID",
		"LeaderId,int,发起人",
		"StartDate,smalldatetime,StartDate",
		"Status,varchar,Status",
		"ReadDate,smalldatetime,ReadDate",
		"ReadUserID,int,ReadUserID",

		  "Tag,varchar,扩展备用属性" //注意该字段不存在于数据库表
		};
            
        /// <summary>
        /// 类对应的表结构信息,
        /// 记录 列的名称、数据类型和大小。
        /// </summary>
        public static string[] FiledsInfo {
            get {
                return m_FiledsInfo;
            }
        }
            

        /// <summary>
        /// 属性索引器
        /// </summary>
        /// <param name=\"index\"></param>
        /// <returns></returns>
        public object this[int index] {
            get {
                return this.getValue(m_FiledsInfo[index].Split(new char[] { ',' })[0]);
            }
            set {
                this.setValue(m_FiledsInfo[index].Split(new char[] { ',' })[0], value);
            }
        }
            
        /// <summary>
        /// 重载属性索引器
        /// </summary>
        /// <param name=\"name\"></param>
        /// <returns></returns>
        public object this[string name] {
            get {
                return this.getValue(name);
            }
            set {
                this.setValue(name, value);
            }
        }       
	 
        /// <summary>
        /// 根据属性名称赋值
        /// 请注意参数name必须完全等于类的某个属性，可以忽略大小写，
        /// </summary>
        /// <param name="name">属性名称</param>
        /// <param name="value">属性值</param>
        public void setValue(string name, object value)
        {
            PropertyInfo pinfo = this.GetType().GetProperty(name, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);
            if (pinfo != null)
            {
                try
                {
                    pinfo.SetValue(this, Convert.ChangeType(value, pinfo.PropertyType), null);
                }
                catch
                {
                    throw new System.Exception("输入参数转换格式时出错！\n输入参数：" + value.ToString() + "\n转换格式：" + pinfo.PropertyType.ToString());
                }

            }
        }

        /// <summary>
        /// 根据属性名称取值
        /// 请注意参数name必须完全等于类的某个属性，可以忽略大小写，
        /// </summary>
        /// <param name="name">属性名称</param>
        public object getValue(string name)
        {
            PropertyInfo pinfo = this.GetType().GetProperty(name, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);
            if (pinfo != null)
                return pinfo.GetValue(this, BindingFlags.IgnoreCase, null, null, null);
            else
                return null;
        }
        #endregion
			     
	}
}